package com.xm.storage.listener;

import com.alibaba.fastjson2.JSON;
import com.xm.common.entity.dto.Client;
import com.xm.common.entity.vo.request.RuntimeDetailVO;
import com.xm.storage.utils.InfluxDbUtils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class KafkaConsumer {


    @Resource
    InfluxDbUtils influx;

    @KafkaListener(topics = "monitor")
    public void consume(String data) {
        RuntimeDetailVO runtimeDetailVO = JSON.parseObject(data, RuntimeDetailVO.class);
        Client client = influx.findClientByToken(runtimeDetailVO.getToken());
        influx.updateRuntimeDetail(runtimeDetailVO, client);
        log.info("收到消息: {}", data);
    }
}
